<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\wiki\Wiki;

$fileName = '淘宝商品ID-' . date('YmdHis') . '.xlsx';
$filePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
$fp = fopen($filePath, 'w');
fputcsv($fp, ['淘宝商品ID']);

$list = [];
$page = 1;
$pageSize = 20000;
do {
    $list = Wiki::selectByWhere([
        'channel' => Wiki::CHANNEL_TAOBAO,
        'LIMIT' => [($page - 1) * $pageSize, $pageSize],
        'status[!]' => Wiki::STATUS_DEL,
        'ORDER' => ['id' => 'DESC']
    ],
        'channel_spu_id'
    );
    foreach ($list as $taobaoId) {
        $item = [
            $taobaoId
        ];
        fputcsv($fp, $item);
    }
    $page++;
} while ($list);
fclose($fp);

\Biz\tools\Mail::send(['tangyiwan@haohaozhu.com'], '淘宝商品ID', '淘宝商品ID', $filePath);

